package com.james;

import java.util.ArrayList;
import java.util.Scanner;

public class StudentManage {
    public static void main(String[] args) {
        ArrayList<Student> array = new ArrayList<>();
        while (true) {
            System.out.println("----------欢迎------------");
            System.out.println("1 添加");
            System.out.println("2 删除");
            System.out.println("3 修改");
            System.out.println("4 查看");
            System.out.println("5 退出");
            System.out.println("请选择：");
            Scanner sc = new Scanner(System.in);
            String line = sc.nextLine();
            switch (line) {
                case "1":
                    //System.out.println("tianj");
                    addStudent(array);
                    break;
                case "2":
                    delete(array);
                    break;
                case "3":
                    System.out.println("delete");
                    break;
                case "4":
                    //System.out.println("delete");
                    allStudent(array);
                    break;
                case "5":
                    System.out.println("退出");
                    //break;
                    System.exit(0);//jvm退出
            }
        }
    }

    public static void addStudent(ArrayList<Student> array) {
        Scanner sc = new Scanner(System.in);
        System.out.println("输入学号");
        String sid = sc.nextLine();
        System.out.println("输入姓名:");
        String name = sc.nextLine();
        System.out.println("输入年龄");
        String age = sc.nextLine();
        System.out.println("输入地址");
        String address = sc.nextLine();

        Student s = new Student();
        s.setSid(sid);
        s.setAge(age);
        s.setName(name);
        s.setAddress(address);

        array.add(s);
        System.out.println("添加ok");
    }

    public static void allStudent(ArrayList<Student> array) {
        System.out.println("学号\t姓名\t年龄\t地址");
        for (int i = 0; i < array.size(); i++) {
            Student s = array.get(i);
            System.out.println(s.getSid() + "\t" + s.getName() + "\t" + s.getAge() + "\t" + s.getAddress());
        }
    }

    public static void delete(ArrayList<Student> array) {
        Scanner sc = new Scanner(System.in);
        System.out.println("请输入删除的学号");
        String sid = sc.nextLine();
        for (int i = 0; i < array.size(); i++) {
            Student s = array.get(i);
            if(s.getSid().equals(sid)){
                array.remove(i);
                break;
            }
        }
        System.out.println("删除ok");
    }
}
